<template>
<div id="p-main">
    <h3 class="photo-title">
        tabId: {{ title }}，
        length: {{ $store.state.photo.recommendList.length }}
    </h3>
    <div id="p-contents" class="animate">
        <ul>
            <li v-for="(item, i) in $store.state.photo.recommendList" :key="i">
                <a :href="item.path" target="_blank">
                    <p class="news-name" :title="item.title">{{item.title}}</p>
                    <p class="news-time">{{item.passtime}}</p>
                    <img class="news-img" :src="item.image" :alt="item.image">
                </a>
            </li>
            <li class="more" @click="handleMore">加载更多</li>
        </ul>
    </div>
</div>
</template>

<script>
export default {
    name: "recommend",
    // https://api.apiopen.top/getWangYiNews?page=1&count=10
    data() {
        return {
            title: "",
            page: 1,
            count: 15
        }
    },
    beforeRouteEnter (to, from, next) {
        if(to.meta.title) {
            next(vm => {
                vm.title = to.meta.title
            })
        }
    },
    mounted() {
        this.getNewsList()
    },
    methods: {

        // 获取新闻
        getNewsList() {
            if(this.$store.state.photo.recommendList.length === 0) {
                this.$store.dispatch("photo/getRecommendNewsList", {
                    page: this.page,
                    count: this.count
                })
            }
        },

        // 加载更多
        handleMore() {
            this.page++
            this.$store.dispatch("photo/getRecommendNewsList", {
                page: this.page,
                count: this.count
            })
        }
    },
}
</script>

<style scoped>
#p-main {
    height: 100%;
    display: flex;
    flex-direction: column;
}
#p-contents {
    flex: 1;
    overflow: auto;
    margin-bottom: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}
.photo-title {
    border:1px solid red;
    margin:5px 10px 0;
    text-align:center;
    box-shadow: 0 0 8px #bf79f8;
    border-radius: 5px;
}
#p-contents ul {
    word-wrap: break-word;
    padding: 0 15px;
}
#p-contents ul li {
    min-height: 50px;
    border: 1px solid #fc8282;
    padding: 6px 8px;
    margin: 8px auto;
    text-align: center;
    border-radius: 10px;
    box-shadow: 0 0 5px #bf79f8;
}
#p-contents ul li .news-name { 
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    line-height: 40px;
    padding-left: 10px;
    font-size: 20px;
    font-weight: bold;
    text-align: center;
    color: red;
    border-radius: 5px;
    box-shadow: 0 0 3px #8f8e8e;
    transition: all .25s ease;
}
#p-contents ul li .news-name:hover{
    box-shadow: 0 0 20px #006eff;
    cursor: pointer;
}
#p-contents ul li .news-time {
    margin: 3px 0;
    color: #0081d6;
}
#p-contents ul li .news-img {
    margin: 0 auto;
    height: 100%;
}
#p-contents .more {
    line-height: 50px;
    text-align: center;
    border: 1px solid #fc8282;
    box-shadow: 0 0 5px #bf79f8;
    font-size: 20px;
    font-weight: bolder;
    color: red;
}
</style>